// JavaScript Document
function searchType(type)
{
	if (type == '1')
	{
		document.getElementById("search_cid").style.display="inline"
		document.getElementById("search_rid").style.display="none"
	}
	else if (type == '2')
	{
		document.getElementById("search_cid").style.display="none"
		document.getElementById("search_rid").style.display="inline"
	}
	else
	{
		document.getElementById("search_cid").style.display="none"
		document.getElementById("search_rid").style.display="none"		
	}
	var option = document.getElementById('method').childNodes;
	for(var i=0; i<option.length; i++)
	{
		//alert(option[i].value)
		if(option[i].value==type)
		{
			option[i].selected=true;
			//alert('xx');
		}
	}
	//alert(option.length);
}

function getPageSize() {
	 var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}

var autologin = 1;
function login()
{
	var loginname = document.getElementById("loginname").value;
	if (loginname.length <= 1) {
		alert('请输入用户名');
		return false;
	}
	var loginpwd = document.getElementById("loginpwd").value;
	if (loginpwd.length <= 1) {
		alert('请输入密码');
		return false;
	}
	//var logincknum = document.getElementById("logincknum").value;
	//if (logincknum.length <= 1) {
		//alert('请输入验证码');
		//return false;
	//}
	$.post("login.php", "loginname=" + loginname + "&loginpwd=" + loginpwd + "&autologin=" + autologin +  "&" + new Date().valueOf(),
  function(data){
    	if(data == 'OK')
	{
		document.getElementById("userpanel").innerHTML = '登录成功';
		window.location.reload();
	}
	else
	{
		var msg = data;
		if(msg == 'ckerror')
		{
			alert('验证码错误');
		}
		else if(msg == 'nock')
		{
			alert('没有输入验证码');
		}
		else if(msg == 'empty')
		{
			alert('您没有提交用户名和密码');
		}
		else
		{
			alert(data);
		}
		showck();
		return;
	}
  }); 
	//var myAjax = new Ajax.Request("login.php",{method: 'POST',parameters: "loginname=" + loginname + "&loginpwd=" + loginpwd + "&autologin=" + autologin +  "&" + new Date().valueOf(),onComplete: loginOK});
}

function loginOK(res)
{
	if(res.responseText == 'OK')
	{
		document.getElementById("userpanel").innerHTML = '登录成功';
		window.location.reload();
	}
	else
	{
		var msg = res.responseText;
		if(msg == 'ckerror')
		{
			alert('验证码错误');
		}
		else if(msg == 'nock')
		{
			alert('没有输入验证码');
		}
		else if(msg == 'empty')
		{
			alert('您没有提交用户名和密码');
		}
		else
		{
			alert(res.responseText);
		}
		showck();
		return;
	}
}

function loginOut()
{
	var url = 'login.php?action=out';
	var myAjax = new Ajax.Request(url,{onComplete: loginOutOK});
}

function loginOutOK(ret)
{
	window.location = 'index.php';
}

function showck(){
	var rand = new Date().valueOf();
	document.getElementById('ckimg').src = 'ck.php?size=90,25,12&' + rand;
}

function copyUrl(head,url){
	var content='';
	content+=url;
	content+= '\r\n"'+head+'"这个教学资源不错，推荐给你。';
	window.clipboardData.setData("Text",content);
	alert("按 CTRL+V，粘贴到协同办公软件，QQ 或 MSN 上发给好友吧 *^-^* ");
}